package com.gd.iot.energy.controller.systemadmin;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.systemadmin.dto.PriceSaveDTO;
import com.gd.iot.energy.pojo.systemadmin.vo.EnumVO;
import com.gd.iot.energy.pojo.systemadmin.vo.PricePageVO;
import com.gd.iot.energy.pojo.systemadmin.vo.PriceVO;
import com.gd.iot.energy.service.systemadmin.PriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 系统管理-参数管理-价格管理
 *
 * @author kris
 * @date Created at 2020/8/3 10:50
 */
@Api(value = "系统管理-参数管理-价格管理",tags = "系统管理-参数管理-价格管理")
@RestController
@RequestMapping("/admin/price")
public class PriceController {
    @ApiOperation("获取价格分页列表")
    @SystemLogRecordMonitor("获取价格分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "pageNum", value = "页码", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderColumn", value = "排序字段", dataType = "string", paramType = "query", example = "", required = false),
            @ApiImplicitParam(name = "orderType", value = "排序类型", dataType = "string", paramType = "query", example = "", required = false),
    })
    @PostMapping("/getPageList")
    public ResponseEntity<PageVO<PricePageVO>> getPageList(
            @RequestParam(value = "pageSize",required = false,defaultValue = "10")Integer pageSize,
            @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum,
            @RequestParam(value = "orderColumn",required = false,defaultValue = "id") String orderColumn,
            @RequestParam(value = "orderType",required = false,defaultValue = "asc") String orderType
    ) {

        PageVO<PricePageVO> pageVO = metermodelService.getPricePageVOs(pageSize,pageNum,orderColumn,orderType);
        return new ResponseEntity<>(pageVO);
    }

    @Autowired
    private PriceService metermodelService;

    @ApiOperation("获取价格列表")
    @SystemLogRecordMonitor("获取价格列表")
    @PostMapping("/getList")
    public ResponseEntity<List<PriceVO>> getList() {

        List<PriceVO> metermodelVOs = metermodelService.getPriceVOs();
        return new ResponseEntity<>(metermodelVOs);
    }

    @ApiOperation("获取价格")
    @SystemLogRecordMonitor("获取价格")
    @PostMapping("/get")
    public ResponseEntity<PriceSaveDTO> get(Integer id){
        PriceSaveDTO roleVO = metermodelService.getPrice(id);
        return new ResponseEntity<>(roleVO);
    }

    @ApiOperation("新增价格")
    @SystemLogRecordMonitor("新增价格")
    @PostMapping("/add")
    public ResponseEntity<Long> add(@RequestBody PriceSaveDTO priceSaveDTO){
        Long id = metermodelService.add(priceSaveDTO);
        return new ResponseEntity<>(id);
    }

    @ApiOperation("更新价格")
    @SystemLogRecordMonitor("更新价格")
    @PostMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody PriceSaveDTO priceSaveDTO){
        boolean res = metermodelService.update(priceSaveDTO);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("删除价格")
    @SystemLogRecordMonitor("删除价格")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestBody List<Integer> ids){
        boolean res = metermodelService.delete(ids);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("获取相关枚举")
    @SystemLogRecordMonitor("获取相关枚举")
    @PostMapping("/getEquipmentType")
    public ResponseEntity<Map<String, List<EnumVO>>> getEquipmentType(){
        Map<String, List<EnumVO>> enums = metermodelService.getEnums();
        return new ResponseEntity<>(enums);
    }
}
